﻿using System.Data;
using System.Data.SqlClient;

namespace common
{
    public class sqlserver_helper : db_helper
    {
        public static System.Data.DataTable get_data_table(string sql)
        {
            SqlConnection con = new SqlConnection(GetConnString());
            SqlCommand com = new SqlCommand();

            com.Connection = con;
            com.CommandText = sql;
            SqlDataAdapter ada = new SqlDataAdapter();
            ada.SelectCommand = com;
            DataSet ds = new DataSet();
            ada.Fill(ds);
            com.Dispose();

            DataTable dt = new DataTable();
            dt = ds.Tables[0];
            return dt;
        }

        public static int ExecuteNonQuery(string Query)
        {
            int Result;

            SqlConnection con = new SqlConnection(GetConnString());
            con.Open();
            SqlCommand com = new SqlCommand(Query, con);
            Result = com.ExecuteNonQuery();
            con.Close();
            return Result;
        }

        public static string GetConnString()
        {
            string strCon = "server=" + server + ";database=;uid=" + uid + ";pwd=" + pwd + ";";
            return strCon;
        }
    }
}